<div class="bjui-pageHeader">
    <form id="pagerForm" data-toggle="ajaxsearch" action="${request.getContextPath()}/ProductionRate/productionRate" method="post">
        <div class="bjui-searchBar">
            <g:hiddenField name="SYS_QUERY_NAME" value="productionRate" />
            <g:hiddenField name="EXPORT_CONTENT_NAME" value="Excel" />
            <label >产品编码：</label>&nbsp;
            <input type="text" name="partName"  value="${partName}"/>
            <label >图号：</label>&nbsp;
            <input type="text" name="tuhao" value="${tuhao}"/>
            <label >订单号：</label>&nbsp;
            <input type="text" name="parentId" value="${parentId}"/>
            <label >产出率小于：</label>&nbsp;
            <input type="text" name="yield" value="${yield}"/>
            <label >报废率大于：</label>&nbsp;
            <input type="text" name="scrapRatio" value="${scrapRatio}"/>
            <label >订单状态：</label>&nbsp;
        <g:select name="startedState" from="${orderStatusAnalysisStartedList}" data-toggle="selectpicker" data-live-search="true" optionKey="doc_status" optionValue="doc_state" value="${startedState}" noSelection="['':'ALL']" />&nbsp;
            <label >时间段：</label>&nbsp;
            <input type="text" name="startTime" readonly value="${startTime}" data-rule="required" data-pattern="yyyy-MM-dd"  data-toggle="datepicker" placeholder="FROM">
            <input type="text" name="endTime" readonly value="${endTime}" data-rule="required" data-pattern="yyyy-MM-dd" data-toggle="datepicker" placeholder="TO">&nbsp;&nbsp;
            <button type="submit" class="btn-default" data-icon="search">查询</button>&nbsp;
            <button type="button" class="btn-blue" onclick="javascript:bjuiExportExl('#pagerForm','${request.getContextPath()}/OutsourcedProcessing/exportExcel')" data-icon="file-excel-o" title="导出Excel">导出</button>&nbsp;
        </div>
    </form>
</div>

<div class="bjui-pageContent">
    <g:if test="${productionRate.size() > 0}">
        <table  data-toggle="tablefixed" data-width="100%" data-nowrap="true">
            <thead>
            <tr id="t1">
                <g:each in="${tableHeadList}" status="j" var="headInstance">
                    <g:if test="${headInstance!='RN'}">
                        <th  width="125"><g:message code="${headInstance}" default="${headInstance}"/></th>
                    </g:if>
                </g:each>
            </tr>
            </thead>
            <tbody>
            <g:if test="${productionRate.size()>0}">
                <g:each in="${productionRate}" status="i" var="dataInstance">
                    <tr>
                        <g:each in="${tableHeadList}" status="j" var="headInstance">
                            <g:if test="${headInstance=='PO_QTY'}">
                                <td name="PO${i}">${dataInstance["${headInstance}"]}</td>
                            </g:if>
                            <g:elseif test="${headInstance=='IN_QTY'}">
                                <td name="IN${i}">${dataInstance["${headInstance}"]}</td>
                            </g:elseif>
                            <g:elseif test="${headInstance=='SHIP_QTY'}">
                                <td name="SHIP${i}">${dataInstance["${headInstance}"] }</td>
                            </g:elseif>
                            <g:elseif test="${headInstance=='SCRAP_QTY'}">
                                <td name="SCRAP${i}">${dataInstance["${headInstance}"] }</td>
                            </g:elseif>
                            <g:elseif test="${headInstance=='SCRAPRATIO'}">
                                <td name="SCRAPRATIO${i}">${dataInstance["${headInstance}"] }</td>
                            </g:elseif>
                            <g:elseif test="${headInstance!='RN'}">
                                <td>${dataInstance["${headInstance}"]}</td>
                            </g:elseif>

                        </g:each>
                    </tr>
                </g:each>
                <tr>
                    <td colspan="6">小计</td>
                    <td name="POSHOW"></td>
                    <td name="INSHOW"></td>
                    <td name="SHIPSHOW"></td>
                    <td name="SCRAPSHOW"></td>

                </tr>
                <tr>
                    <td colspan="6">合计</td>
                    <td>${productionRateSumQty.SUM_PO[0]}</td>
                    <td>${productionRateSumQty.SUM_IN[0]}</td>
                    <td>${productionRateSumQty.SUM_SHIP[0]}</td>
                    <td>${productionRateSumQty.SUM_SCRAP[0]}</td>
                </tr>

            </g:if>
            <g:else>
                <g:render template="../template/emptyPanel" />
            </g:else>
            </tbody>
        </table>
    </g:if>
</div>
<g:render template="../template/pagination" />
<script>
    $(function(){
        var poQty=0;
        var inQty=0;
        var shipQty=0;
        var scrapQty=0;
        for(var i=0;i<${productionRate.size()};i++){

            var po='PO'+i
            var poAdd=$("td[name='"+po+"']").text()==''?0:parseInt($("td[name='"+po+"']").text());
            poQty+=poAdd;

            var inn='IN'+i
            var innAdd=$("td[name='"+inn+"']").text()==''?0:parseInt($("td[name='"+inn+"']").text());
            inQty+=innAdd;

            var ship='SHIP'+i
            var shipAdd=$("td[name='"+ship+"']").text()==''?0:parseInt($("td[name='"+ship+"']").text());
            shipQty+=shipAdd;

            var scrap='SCRAP'+i
            var scrapAdd=$("td[name='"+scrap+"']").text()==''?0:parseInt($("td[name='"+scrap+"']").text());
            scrapQty+=scrapAdd;
        }

        $("td[name='POSHOW']").html(poQty);
        $("td[name='INSHOW']").html(inQty);
        $("td[name='SHIPSHOW']").html(shipQty);
        $("td[name='SCRAPSHOW']").html(scrapQty);

        for(var i=0;i<${productionRate.size()};i++) {
            var partFinTime = "SCRAPRATIO" + i;
            var partFinTimeJudge = parseFloat($("td[name='" + partFinTime + "']").text())
            if (partFinTimeJudge >= 0.1 && partFinTimeJudge < 0.2) {
                $("td[name='" + partFinTime + "']").css("background-color", "#FFFF00")
                $("td[name='" + partFinTime + "']").nextAll().css("background-color", "#FFFF00")
                $("td[name='" + partFinTime + "']").prevAll().css("background-color", "#FFFF00")
            } else if (partFinTimeJudge >= 0.2) {
                $("td[name='" + partFinTime + "']").css("background-color", "#FF0000")
                $("td[name='" + partFinTime + "']").nextAll().css("background-color", "#FF0000")
                $("td[name='" + partFinTime + "']").prevAll().css("background-color", "#FF0000")
            }
        }
    })
</script>
